﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using fsw.Common;
using fsw.Web.UI;

namespace fsw.Web.Mould
{
    public partial class Edit : Web.UI.ManagePage
    {
        private int id = 0;
        protected Model.Admin model_admin;
        protected Model.Mould Mould_Model;
        protected string _Url;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.id = DTRequest.GetQueryInt("id");
            this._Url = DTRequest.GetUrlReferrer();
            if (!this._Url.ToLower().Contains("list.aspx")) this._Url = "List.aspx";
            model_admin = GetAdminInfo();
            if (model_admin.TypeId > 1) Response.End();
            if (this.id == 0)
            {
                Response.End();
                return;
            }
            if (!new BLL.Mould().Exists(this.id))
            {
                Response.End();
                return;
            }
            if (!Page.IsPostBack)
            {
                Mould_Model = ShowInfo(this.id);
            }
            if (DTRequest.IsPost())
            {
                Response.Write(DoEdit());
                Response.End();
            }
        }
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        private Model.Mould ShowInfo(int _id)
        {
            BLL.Mould bll = new BLL.Mould();
            Model.Mould model = bll.GetModel(_id);
            return model;
        }
        private string DoEdit()
        {
            try
            {
                string MouldName = DTRequest.GetFormString("MouldName");//项目名称                            
                int OrderNo = DTRequest.GetFormInt("OrderNo");//排序            
                Mould_Model = ShowInfo(this.id);
                Mould_Model.MouldName = MouldName;               
                Mould_Model.OrderNo = OrderNo;
                BLL.Mould bll = new BLL.Mould();
                if (bll.Update(Mould_Model))
                {
                    AdminAddLog(model_admin.Id, model_admin.UserName, "更新" + MouldName + "模块成功!");
                    CacheHelper.ClearCache();
                    return JsonErr("success", "更新模块成功!");
                }
            }
            catch { }
            return JsonErr("error", "参数错误 ");
        }
    }
}